package com.randi.system.domain.entity.sysLog;

import com.baomidou.mybatisplus.annotation.*;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import com.randi.common.annotation.Excel;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.data.annotation.Transient;

import java.io.Serializable;
import java.util.Date;

/**
 * @author ziye
 */
@Data
@TableName("sys_log_login")
@ApiModel(value = "SysLoginInfo", description = "登录日志")
public class SysLogLogin implements Serializable {

    @Excel(name = "访问ID")
    @TableId(value = "info_id", type = IdType.ASSIGN_ID)
    @JsonSerialize(using = ToStringSerializer.class)
    @ApiModelProperty(value = "访问ID")
    private Long infoId;

    @Excel(name = "用户名称")
    @TableField(value = "`user_name`")
    @ApiModelProperty(value = "用户名称")
    private String userName;

    @Excel(name = "登录IP地址")
    @TableField(value = "`ip_address`")
    @ApiModelProperty(value = "登录IP地址")
    private String ipAddress;

    @Excel(name = "登录地点")
    @TableField(value = "`login_location`")
    @ApiModelProperty(value = "登录地点")
    private String loginLocation;

    @Excel(name = "浏览器类型")
    @TableField(value = "`browser`")
    @ApiModelProperty(value = "浏览器类型")
    private String browser;

    @Excel(name = "操作系统")
    @TableField(value = "`os`")
    @ApiModelProperty(value = "操作系统")
    private String os;

    @ApiModelProperty(value = "登录类型")
    @TableField(value = "`type`")
    private Integer type;

    @Excel(name = "登录状态", readConverterExp = "0=成功,1=失败")
    @TableField(value = "`status`")
    @ApiModelProperty(value = "登录状态")
    private Integer status;

    @Excel(name = "提示消息")
    @TableField(value = "`message`")
    @ApiModelProperty(value = "提示消息")
    private String message;

    @Excel(name = "访问时间", dateFormat = "yyyy-MM-dd HH:mm:ss")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @TableField(value = "`login_time`")
    @ApiModelProperty(value = "访问时间")
    private Date loginTime;

    @Transient
    public String getKey() {
        return this.infoId == null ? "" : this.infoId.toString();
    }

    @Transient
    public String getStatusName() {
        return this.status == null || this.status == 0 ? "成功" : "失败";
    }
}
